package com.aistar.controller;

import com.aistar.pojo.Customer;
import com.aistar.pojo.DynamicComment;
import com.aistar.pojoVO.DynamicCommentVO;
import com.aistar.service.DynamicCommentService;
import com.aistar.serviceVO.DynamicCommentVOService;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
@RequestMapping("/dynamicComment")
public class DynamicCommentController {
    private final DynamicCommentService dynamicCommentService;
    private final DynamicCommentVOService dynamicCommentVOService;

    @Autowired
    public DynamicCommentController(DynamicCommentService dynamicCommentService,
                                    DynamicCommentVOService dynamicCommentVOService) {
        this.dynamicCommentService = dynamicCommentService;
        this.dynamicCommentVOService = dynamicCommentVOService;
    }

    @RequestMapping("/add")
    @ResponseBody
    public ServerResponse add(@RequestBody DynamicComment dynamicComment) {
        dynamicComment.setCustomerCommentTime(new Date());
        System.out.println(dynamicComment);
        return dynamicCommentService.add(dynamicComment);
    }

    @RequestMapping("/getByFatherId")
    @ResponseBody
    public ServerResponse getByFatherId(Integer fatherId) {
        return dynamicCommentVOService.getByFatherId(fatherId);
    }
}
